
#include <iostream>
#include <cassert>
#include <fstream>
#include <chrono>
#include "geometry.h"
#include "fluid.h"
#include "boundConds.h"
#include "spaceDiscr.h"
#include "timeDiscr.h"
#include "solver.h"
// 应该写成单元测试的样子  保证调试好弄
// g++17 ../src/test_main.cpp ../src/geometry.cpp
// g++17 ../src/test_main.cpp ../src/geometry.cpp ../src/fluid.cpp ../src/boundConds.cpp
// clang++17 ../src/main.cpp ../src/geometry.cpp ../src/fluid.cpp ../src/boundConds.cpp ../src/spaceDiscr.cpp ../src/timeDiscr.cpp  ../src/solver.cpp  ../src/utility.cpp
// clang++17 -Wall  ../main.cpp ../geometry.cpp ../fluid.cpp ../boundConds.cpp ../spaceDiscr.cpp ../timeDiscr.cpp  ../solver.cpp  ../utility.cpp
// 使用 kd 搜索树进行壁面距离求值也是不错的
using namespace std;
int main()
{
    auto tbeg = chrono::steady_clock::now();
    Config cfg;
    // 读边界文件 网格文件 计算几何量,
    Geometry geometric(cfg);
    geometric.PrintBoundary(cout);
    geometric.InitMetrics();

    Fluid flow(cfg, geometric.imax, geometric.jmax);
    flow.InitFlow();

    if (cfg.GetEquationType() == Equation_t::Euler)
    {
        flow.PrintEuler();

        flow.DependentVarsAllEuler();

        BoundConds boundary(cfg, geometric, flow);
        boundary.BoundaryConditionsEuler(); // 没问题

        SpaceDiscr spaceDiscrete(cfg, geometric, flow);
        TimeDiscr tadv(cfg, geometric,
                       flow, spaceDiscrete,
                       boundary);

        Solver flowSolver(cfg, tadv, flow, geometric.coord,
                          spaceDiscrete);
        // 可以再提前划分
        // 可以在此划分分水岭 是 euler or NS  单线进 单线出
        flowSolver.FlowSolverEuler();
    }
    // NS equation
    else
    {
        flow.PrintNS();
        flow.DependVarsAllNS();
        BoundConds boundary(cfg, geometric, flow);
        boundary.BoundaryConditionsNS();

        SpaceDiscr spaceDiscrete(cfg, geometric, flow);
        TimeDiscr tadv(cfg, geometric,
                       flow, spaceDiscrete,
                       boundary);

        Solver flowSolver(cfg, tadv, flow, geometric.coord,
                          spaceDiscrete);
        // 可以再提前划分
        // 可以在此划分分水岭 是 euler or NS  单线进 单线出
        flowSolver.FlowSolverNS();
    }

    auto tend = chrono::steady_clock::now();
    auto runTime = chrono::duration_cast<chrono::duration<double>>(tend - tbeg);
    cout << "\nrun time = " << runTime.count() << endl;
    return 0;
}
